﻿using MediatR;
using RBAC.MaHaiBo.API.Application.Command.SlaughterCommand;
using RBAC.MaHaiBo.Entity.Traceability;
using RBAC.MaHaiBo.Service.TraceabilityService;

namespace RBAC.MaHaiBo.API.Application.CommandHandlers.SlaughterHandler
{
    public class AddSlaughterCommandHamdler:IRequestHandler<AddSlaughterCommand,int>
    {
        /// <summary>
        /// 屠宰服务层
        /// </summary>
        ISlaughterService service;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service">屠宰服务层</param>
        public AddSlaughterCommandHamdler(ISlaughterService service)
        {
            this.service = service;
        }

        public async Task<int> Handle(AddSlaughterCommand request, CancellationToken cancellationToken)
        {
            return await service.AddSlaughter(new Entity.Traceability.Slaughter()
            {
                slaughterid= request.slaughterid,
                LOT = request.LOT,
                counterbalance = request.counterbalance,
                Arrivaltime = request.Arrivaltime,
                Slaughtertime = request.Slaughtertime,
                Uid = request.Uid,
                AddName = request.AddName,
                AddTime = request.AddTime,
                UpdName = request.UpdName,
                UpdTime = request.UpdTime,
                DelName = request.DelName,
                DelTime = request.DelTime
            });
        }
    }
}
